﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AIToolsQRCodeConfig
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {

        const int MAX_ITEM_COUNT = 36;

        public MainWindow()
        {
            InitializeComponent();

            for (int i = 0; i < MAX_ITEM_COUNT; i++)
            {
                Button button = new Button();
                button.Content = "按钮 " + (i+1);
                button.Margin = new Thickness(5);
                button.Height = 100;
                button.Width = 100;
                mainUniformGrid.Children.Add(button);
            }

        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            UpdateGridLayout();
        }

        private void UpdateGridLayout()
        {
            if (mainUniformGrid == null) return;

            // 计算基于窗口大小的合适列数
            double itemWidth = 120; // 每个项目的期望宽度
            double itemHeight = 120; // 每个项目的期望高度

            int columns = Math.Max(1, (int)(this.ActualWidth / itemWidth));
            if (columns > mainUniformGrid.Children.Count) columns = mainUniformGrid.Children.Count;

            int rows = (int)Math.Ceiling((double)mainUniformGrid.Children.Count / columns);

            mainUniformGrid.Columns = columns;
            mainUniformGrid.Rows = rows;
        }
    }
}
